package com.qzsoft.zhjd.server.modules.asphalt.handler;

import java.util.Date;

import com.qzsoft.zhjd.server.common.utils.NumberUtils;
import com.qzsoft.zhjd.server.modules.asphalt.entity.CollectAsphaltDataEntity;
import com.qzsoft.zhjd.server.modules.asphalt.entity.CollectAsphaltMatchEntity;
import com.qzsoft.zhjd.server.modules.asphalt.model.CollectDataModel;

/**
 * @ClassName AsphaltDataHandler
 * @Description 生产数据处理
 * @author linhuawei
 * @since 2022-02-09
 */
public class AsphaltDataHandler {

    /**
     * @Title coverToData
     * @Description 转化生产数据主表数据
     * @param model 采集数据
     * @param match 生产配比
     * @return 生产数据主表数据
     */
    public static CollectAsphaltDataEntity coverToData(CollectDataModel model, CollectAsphaltMatchEntity match) {
        CollectAsphaltDataEntity data = new CollectAsphaltDataEntity();
        if (null != match) {
            data.setBaseCode(match.getBaseCode());
            data.setProjectId(match.getProjectId());
            data.setStationCode(match.getStationCode());
            data.setMatchCode(match.getMatchCode());
            data.setMatchName(match.getMatchName());
            data.setMatchType(match.getMatchType());
        } else {
            // 根据拌合站编号处理基地编号，JD##AC#
            String stationCode = model.getStationCode();
            String baseCode = null;
            if (null != stationCode && 7 == stationCode.length()) {
                baseCode = stationCode.substring(0, 4);
            }
            data.setBaseCode(baseCode);
            data.setStationCode(model.getStationCode());
            data.setMatchCode(model.getMatchCode());
        }
        data.setDischargeTime(model.getDischargeTime());// 出料时间
        data.setDischargeTemperature(NumberUtils.setScale(model.getAsphaltTemp(), 2));// 出料温度
        data.setSluiceTemperature(NumberUtils.setScale(model.getSluiceTemp(), 2));// 溜槽温度
        data.setBatchWeight(NumberUtils.setScale(model.getBatchWeight(), 2));// 盘重
        data.setMixingDuration(model.getMixingDuration());// 搅拌时长
        data.setAsphaltTemperature(NumberUtils.setScale(model.getAsphaltTemp(), 2));// 沥青温度
        data.setInsertTime(new Date());
        data.setOriginalId(model.getId());// 记录原始数据主键
        return data;
    }

}
